/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package izsla.entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;

/**
 * Image entity.
 */
@Entity
public class Image implements Serializable {

	private static final long serialVersionUID = 1L;
	/**Primary key.*/
	private Long id;

	/**Title of the image.*/
	private String title;

	/** Image file name.*/
	private String imgName;

	/** Trip, the image is assigned to.*/
	private Trip trip;

	/** The uploader of the image.*/
	private TripUser uploader;

	/** The image data.*/
	private byte[] imgData;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getImgName() {
		return imgName;
	}

	public void setImgName(String imgName) {
		this.imgName = imgName;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@ManyToOne
	public Trip getTrip() {
		return trip;
	}

	public void setTrip(Trip trip) {
		this.trip = trip;
	}

	@ManyToOne
	public TripUser getUploader() {
		return uploader;
	}

	public void setUploader(TripUser uploader) {
		this.uploader = uploader;
	}

	@Override
	public String toString() {
		return "izsla.entities.Image[id=" + id + "]";
	}

	@Lob
	@Basic(fetch = FetchType.LAZY)
	@Column(precision = 5 * 1024 * 1024)
	public byte[] getImgData() {
		return imgData;
	}

	public void setImgData(byte[] imgData) {
		this.imgData = imgData;
	}

	@Override
	public boolean equals(Object obj) {
		if(obj == null) {
			return false;
		}
		if(getClass() != obj.getClass()) {
			return false;
		}
		final Image other = (Image) obj;
		if(this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
			return false;
		}
		return true;
	}

	@Override
	public int hashCode() {
		int hash = 5;
		hash = 17 * hash + (this.id != null ? this.id.hashCode() : 0);
		return hash;
	}
}
